package org.study.clickhouse.boot.util;

import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

/**
 * java.sql.Date、java.sql.Time、java.sql.Timestamp 相关工具类
 *
 * @author LENOVO
 */
public final class SqlDateUtils {
    private SqlDateUtils() {
        throw new AssertionError("工具类不能被实例化！！！");
    }

    /**
     * java.util.Date --> java.sql.Date
     */
    public static Date utilDate2SqlDate(java.util.Date utilDate) {
        java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
        return sqlDate;
    }

    /**
     * java.sql.Date --> java.util.Date
     */
    public static java.util.Date sqlDate2UtilDate(java.sql.Date sqlDate) {
        Date utilDate = sqlDate;
        return utilDate;
    }

    /**
     * java.time.LocalDate --> java.sql.Date
     */
    public static Date localDate2SqlDate(LocalDate localDate) {
        Date sqlDate = Date.valueOf(localDate);
        return sqlDate;
    }

    /**
     * java.sql.Date --> java.time.LocalDate
     */
    public static LocalDate sqlDate2LocalDate(Date date) {
        LocalDate localDate = date.toLocalDate();
        return localDate;
    }

    /**
     * java.time.LocalTime --> java.sql.Time
     */
    public static Time localTime2SqlTime(LocalTime localTime) {
        Time time = Time.valueOf(localTime);
        return time;
    }

    /**
     * java.sql.Time --> java.time.LocalTime
     */
    public static LocalTime sqlTime2LocalTime(Time time) {
        LocalTime localTime = time.toLocalTime();
        return localTime;
    }

    /**
     * java.time.LocalDateTime --> java.sql.Timestamp
     */
    public static Timestamp localDateTime2SqlTimestamp(LocalDateTime localDateTime) {
        Timestamp timestamp = Timestamp.valueOf(localDateTime);
        return timestamp;
    }

    /**
     * java.time.LocalDateTime --> java.sql.Timestamp
     */
    public static Timestamp utilDate2SqlTimestamp(java.util.Date date) {
        Timestamp timestamp = new Timestamp(date.getTime());
        return timestamp;
    }

    /**
     * java.sql.Timestamp --> java.time.LocalDateTime
     */
    public static LocalDateTime sqlTimestamp2LocalDateTime(Timestamp timestamp) {
        LocalDateTime localDateTime = timestamp.toLocalDateTime();
        return localDateTime;
    }

    public static void main(String[] args) {
        Timestamp timestamp = utilDate2SqlTimestamp(new java.util.Date());
        System.out.println(timestamp);
    }
}
